<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:c="http://java.sun.com/jsp/jstl/core"	
	template="/resources/scaffold/pageTemplate.xhtml">

	<f:metadata>
		<f:viewParam name="id" value="#{reviewBean.id}"/>
		<f:event type="preRenderView" listener="#{reviewBean.retrieve}"/>
	</f:metadata>

	<ui:param name="pageTitle" value="Create Review"/>

	<ui:define name="header">
		Review
	</ui:define>

	<ui:define name="subheader">
		<c:choose>
			<c:when test="#{!empty reviewBean.id}">
				Edit existing Review
			</c:when>
			<c:otherwise>
				Create a new Review
			</c:otherwise>
		</c:choose>
	</ui:define>

	<ui:define name="footer"/>

	<ui:define name="main">
		<h:form id="create">
			<h:messages globalOnly="true" styleClass="error"/>

			<h:panelGrid columnClasses="label,component,required" columns="3">
				<h:outputLabel for="reviewBeanReviewDate" value="Date:"/>
				<h:panelGroup>
					<h:inputText id="reviewBeanReviewDate" value="#{reviewBean.review.date}"/>
					<h:message for="reviewBeanReviewDate" styleClass="error"/>
				</h:panelGroup>
				<h:outputText/>
				<h:outputLabel for="reviewBeanReviewText" value="Text:"/>
				<h:panelGroup>
					<h:inputText id="reviewBeanReviewText" value="#{reviewBean.review.text}"/>
					<h:message for="reviewBeanReviewText" styleClass="error"/>
				</h:panelGroup>
				<h:outputText/>
				<h:outputLabel value="Author:"/>
				<h:panelGroup>
					<h:commandLink action="#{reviewBean.review.newAuthor}" rendered="#{empty reviewBean.review.author}" value="Create New Author"/>
					<h:panelGrid columnClasses="label,component,required" columns="3" rendered="#{!empty reviewBean.review.author}">
						<h:outputLabel for="reviewBeanReviewAuthorFirstName" value="First Name:"/>
						<h:panelGroup>
							<h:inputText id="reviewBeanReviewAuthorFirstName" value="#{reviewBean.review.author.firstName}"/>
							<h:message for="reviewBeanReviewAuthorFirstName" styleClass="error"/>
						</h:panelGroup>
						<h:outputText/>
						<h:outputLabel for="reviewBeanReviewAuthorLastName" value="Last Name:"/>
						<h:panelGroup>
							<h:inputText id="reviewBeanReviewAuthorLastName" value="#{reviewBean.review.author.lastName}"/>
							<h:message for="reviewBeanReviewAuthorLastName" styleClass="error"/>
						</h:panelGroup>
						<h:outputText/>
						<h:outputLabel for="reviewBeanReviewAuthorEmail" value="Email:"/>
						<h:panelGroup>
							<h:inputText id="reviewBeanReviewAuthorEmail" value="#{reviewBean.review.author.email}"/>
							<h:message for="reviewBeanReviewAuthorEmail" styleClass="error"/>
						</h:panelGroup>
						<h:outputText/>
						<h:outputLabel for="reviewBeanReviewAuthorPhone" value="Phone:"/>
						<h:panelGroup>
							<h:inputText id="reviewBeanReviewAuthorPhone" value="#{reviewBean.review.author.phone}"/>
							<h:message for="reviewBeanReviewAuthorPhone" styleClass="error"/>
						</h:panelGroup>
						<h:outputText/>
					</h:panelGrid>
				</h:panelGroup>
				<h:outputText/>
			</h:panelGrid>

			<div class="buttons">
				<h:commandLink value="Save" action="#{reviewBean.update}" styleClass="btn btn-primary"/>
				<c:choose>
					<c:when test="#{!empty reviewBean.id}">
						<h:link value="Cancel" outcome="view" styleClass="btn btn-primary">
							<f:param name="id" value="#{reviewBean.id}"/>
						</h:link>
						<h:commandLink value="Delete" action="#{reviewBean.delete}" styleClass="btn btn-primary"/>
					</c:when>
					<c:otherwise>
						<h:link value="Cancel" outcome="search" styleClass="btn btn-primary"/>
					</c:otherwise>
				</c:choose>
			</div>
		</h:form>
	</ui:define>

</ui:composition>